package com.gyhy.dumplings.product.controller;

import com.gyhy.dumplings.common.dto.WareDto;
import com.gyhy.dumplings.common.exception.BizCodeEnum;
import com.gyhy.dumplings.common.utils.R;
import com.gyhy.dumplings.product.entity.ProductEntity;
import com.gyhy.dumplings.product.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description:
 * @author: 光影灰翼
 * @date: 2022-09-26 8:36
 * @version: 1.0
 * @email: 978330688@qq.com
 */
@RestController
@RequestMapping("/product")
public class ProductController {

    @Autowired
    private ProductService productService;

    @GetMapping(value = "/listProducts")
    R listProducts() {
        List<ProductEntity> productEntity = productService.listProducts();

        if (productEntity != null) {
            return R.ok().setData(productEntity);
        } else {
            return R.error(BizCodeEnum.PRODUCT_UP_EXCEPTION.getCode(),BizCodeEnum.PRODUCT_UP_EXCEPTION.getMessage());
        }
    }
    @PostMapping(value = "/getWareInfo")
    R getWareInfo(@RequestBody List<WareDto> wareDtoList) {


        List<WareDto> newWareDtoList = productService.listWareDto(wareDtoList);

        if (wareDtoList != null) {
            return R.ok().setData(newWareDtoList);
        } else {
            return R.error(BizCodeEnum.PRODUCT_UP_EXCEPTION.getCode(),BizCodeEnum.PRODUCT_UP_EXCEPTION.getMessage());
        }
    }


}
